package com.fact.actions;

import java.util.ArrayList;
import java.util.Map;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.fact.dto.NavDTO;
import com.fact.dto.SegmentDTO;
import com.fact.dto.UserDTO;
import com.fact.models.LeftNavService;
import com.fact.models.SegmentService;
import com.fact.utils.AppConstant;

public class DashBoard extends BaseAction implements SessionAware{

	private static final long serialVersionUID = -7039465136748446504L;
	private Map<String,Object> session;
	private String page=AppConstant.DASHBOARD;
	private String pageTitle="FMtool-DashBoard";
	LeftNavService leftNodeService=new LeftNavService();
	SegmentService segmentService=new SegmentService();
	
	private int selectedMonth;
	private int selectedYear;
	
	
	public String execute()
	{
		if(selectedMonth==0) selectedMonth=Integer.parseInt(getServletContext().getAttribute("CURRENT_MONTH").toString());
		if(selectedYear==0) selectedYear=Integer.parseInt(getServletContext().getAttribute("CURRENT_YEAR").toString());
		
		if(((UserDTO)session.get("user")).getUserTypeName().equalsIgnoreCase("writer"))
		{
			ArrayList<NavDTO> makeMarketList=leftNodeService.getLeftNavNodeList(((UserDTO)session.get("user")).getUserId());
			ArrayList<SegmentDTO> segmentList=segmentService.getSegmentList();
			
			getServletContext().setAttribute("ALL_MAKE_MARKET", makeMarketList);
			getServletContext().setAttribute("ALL_SEGMENT", segmentList);
			
		}
			return SUCCESS;
	}

	public ServletContext getServletContext()
	{
		return ServletActionContext.getServletContext();
	}

	
	
	public int getSelectedMonth() {
		return selectedMonth;
	}

	public void setSelectedMonth(int selectedMonth) {
		this.selectedMonth = selectedMonth;
	}

	public int getSelectedYear() {
		return selectedYear;
	}

	public void setSelectedYear(int selectedYear) {
		this.selectedYear = selectedYear;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public String getPageTitle() {
		return pageTitle;
	}

	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}
	
	

}
